package com.zr.serviceimpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.ShowAllStationDao;
import com.zr.model.Cdisstation;
import com.zr.model.Cuser;
import com.zr.service.ShowAllStationService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service("showAllStationService")
public class ShowAllStationServiceImpl<T> implements ShowAllStationService{
	
	@Resource
	private ShowAllStationDao<T> showAllStationDao;

	@Override
	public JSONObject getAllStations(int page, int rows,int ids) {
		JSONObject j = new JSONObject();
		j.put("total",showAllStationDao.getStationCount(ids));
		List<Cdisstation> cds = showAllStationDao.getAllStations(page, rows, ids);
		JSONArray js = new JSONArray();
		for (Cdisstation cd : cds) {
			JSONObject u = new JSONObject();
			u.put("disid", cd.getDisid());
			u.put("disname", cd.getDisname());
			u.put("distype", cd.getCstationtype().getDistype());
			u.put("disstate", cd.getCstationtype().getDisstate());
			u.put("uname", cd.getCuser().getUname());
			u.put("uid", cd.getCuser().getUid());
			u.put("disscope", cd.getDisscope());
			u.put("disprice", cd.getDisprice());
			u.put("instation", showAllStationDao.getStationNameByDisid(cd.getInstation()));
			u.put("instationId", showAllStationDao.getStationIdByDisid(cd.getInstation()));
			js.add(u);
		}
		j.put("rows", js);
		return j;
	}

}
